<template>
  <el-card
    class="patrol-maintenance work-bench-team__card"
    shadow="never"
    body-style="display: flex; flex-direction: column; height: calc(100% - 20px); padding: 10px 15px;"
  >
    <div class="patrol-maintenance__header work-bench-team__card__header">
      <span class="work-bench-team__card__title patrol-maintenance__title">巡检保养 (今日)</span>
    </div>
    <div v-if="list && list.length" class="work-bench-team__card__body patrol-maintenance__body">
      <el-carousel
        class="patrol-maintenance__carousel"
        height="100%"
        direction="vertical"
        :autoplay="true"
        :loop="true"
      >
        <el-carousel-item v-for="i in Math.ceil(list.length / 5)" :key="i">
          <div
            class="patrol-maintenance__item"
            v-for="(item, index) in list.slice((i - 1) * 5, i * 5)"
            :key="item.id"
            :class="{ 'patrol-maintenance__item--2': index % 2 === 1 }"
          >
            <div class="patrol-maintenance__item__details">{{ item.planName }}</div>
            <div class="patrol-maintenance__item__type">{{ { 1: '巡检', 2: '保养' }[item.planType] }}</div>
            <div class="patrol-maintenance__item__status" :class="statusClass[item.handleStatus]">
              {{ statusName[item.handleStatus] }}
            </div>
          </div>
        </el-carousel-item>
      </el-carousel>
    </div>
    <div v-else class="patrol-maintenance__no-data">暂无数据!</div>
  </el-card>
</template>

<script>
// ============================== 导入依赖 ============================== //

import dashboardTeamApi from '@admin/views/Workbench/WorkbenchTeam/api'
import state from './state'

// ============================== 导出组件 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'PatrolMaintenance',

  props: {
    /**
     * 班组ID
     */
    teamId: { type: String, default: '' },
  },

  data() {
    return {
      ...state(),
    }
  },

  mounted() {
    this.$nextTick(() => {
      dashboardTeamApi.queryTeamPlanList({
        type: 1,
        teamId: this.teamId,
        tenantNo: 0,
      }).then((res) => {
        this.list = res.planTaskDto || []
      })
    })
  },
}
</script>

<style lang="scss">
@import './index.scss';
</style>
